import tkinter as tk
from tkinter import *
import client_socket as cl	#网络套接字模块

def register():#注册程序
	def click_reg():#点击注册
		u_user=user.get()
		u_pwd_1=pwd_1.get()
		u_pwd_2=pwd_2.get()
		u_tel=tel.get()
		u_mail=mail.get()
		if u_pwd_1 != u_pwd_2:
			Label(sign,text = '两次密码输入不一致',fg='red',width=30).grid(row=13,columnspan=2)
		#reg_data = dc.Data_conding()
		reg_return=cl.Data_Val('reg_info',u_user,u_pwd_1,u_tel,u_mail)
		if reg_return == '注册成功':
			#messagebox.showinfo(title='注册消息',message='注册成功,点击返回登陆')
			Label(sign,text = reg_return,fg='green',width=30).grid(row=13,columnspan=2)
		else:
			Label(sign,text = reg_return,fg='red',width=30).grid(row=13,columnspan=2)

	def s_exit():#取消注册
		sign.destroy()

	sign = tk.Toplevel()
	sw = sign.winfo_screenwidth()#获取屏幕宽度
	sh = sign.winfo_screenheight()#获取屏幕高度
	#cw = sign.winfo_width()
	#ch = sign.winfo_height()
	cw = 300
	ch = 400
	x = (sw-cw)/2#获取减去程序所占宽度后屏幕一半的宽度
	y = (sh-ch)/2#获取减去程序所占高度后屏幕一半的高度
	sign.geometry('%dx%d+%d+%d'%(cw,ch,x,y))#设置窗口大小和显示位置
	sign.resizable(0,0)
	sign.title('注册98k创意运维管理系统')
	user=StringVar()
	pwd_1=StringVar()
	pwd_2=StringVar()
	tel=StringVar()
	mail=StringVar()
	code=StringVar()
	#mv=Frame(sign,width=400,height=500).grid()
	#lv=Frame(mv,width=200,height=500,bg='red').grid(row=0,column=0)
	#rv=Frame(mv,width=200,height=500,bg='green').grid(row=0,column=1)

	Label(sign,text=' ',font=('新宋体',12)).grid(row=0,column=0)
	Label(sign,text='请输入账号:',font=('新宋体',12),width=14,anchor=E).grid(row=1,column=0)
	Entry(sign,width=23,bd=2,textvariable=user).grid(row=1,column=1,sticky=W)
	Label(sign,text='账号只能是英文字母,不区分\n大小写,不能使用特殊符号',font=('新宋体',9),fg='gray',width=26).grid(row=2,column=1)

	Label(sign,text='请输入密码:',font=('新宋体',12),width=14,anchor=E).grid(row=3,column=0,sticky=E)
	Entry(sign,width=23,bd=2,textvariable=pwd_1).grid(row=3,column=1,sticky=W)
	Label(sign,text='密码由英语大小写字母、数字\n的组合,不能使用标点符号',font=('新宋体',9),fg='gray',width=26).grid(row = 4,column=1,sticky=W)

	Label(sign,text='重复输入密码:',font=('新宋体',12),width=14,anchor=E).grid(row=5,column=0)
	Entry(sign,width=23,bd=2,textvariable=pwd_2).grid(row=5,column=1,sticky=W)
	Label(sign,text='请重复输入密码',font=('新宋体',9),fg='gray',width=26).grid(row=6,column=1)

	Label(sign,text='请输入手机号:',font=('新宋体',12),width=14,anchor=E).grid(row=7,column=0)
	Entry(sign,width=23,bd=2,textvariable=tel).grid(row=7,column=1)
	Label(sign,text='请输入由11位数字组成的手机\n号码',font=('新宋体',9),fg='gray',width=26).grid(row=8,column=1)

	Label(sign,text='请输入邮箱:',font=('新宋体',12),width=14,anchor=E).grid(row=9,column=0,sticky=E)
	Entry(sign,width=23,bd=2,textvariable=mail).grid(row=9,column=1)
	Label(sign,text='请输入正确的邮箱用于发送邀\n请码,否则无法注册成功',font=('新宋体',9),fg='gray',width=26).grid(row=10,column=1)

	Label(sign,text='请输入邀请码:',font=('新宋体',12),width=14,anchor=E).grid(row=11,column=0)
	Entry(sign,width=23,bd=2,textvariable=code).grid(row=11,column=1)
	Label(sign,text='请输入正确的邀请码,以便用于\n成功注册',font=('新宋体',9),fg='gray',width=26).grid(row=12,column=1)

	Button(sign,text='点击注册',bg='green',font=('新宋体',14,'bold'),command=click_reg).place(x=40,y=355)
	Button(sign,text='返回登陆',bg='red',font=('新宋体',14,'bold'),command=s_exit).place(x=160,y=355)

